package logic

import (
	"context"
	"errors"
	"shuqi-novel/mysql"

	"shuqi-novel/userrpc/internal/svc"
	"shuqi-novel/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ArticleAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewArticleAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleAddLogic {
	return &ArticleAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 用户详情
func (l *ArticleAddLogic) ArticleAdd(in *userrpc.ArticleAddRequest) (*userrpc.UserDetailResponse, error) {
	// todo: add your logic here and delete this line

	var article = mysql.Article{
		UserId:  in.UserId,
		Title:   in.Title,
		About:   in.About,
		Type:    in.Type,
		Content: in.Content,
	}
	err := article.ArticleAdd(mysql.DB)
	if err != nil {
		return nil, errors.New("添加失败")
	}

	return &userrpc.UserDetailResponse{
		ArticleId: int64(article.ID),
	}, nil
}
